<?php
/**
 * Created by PhpStorm.
 * User: dev
 * Date: 11/11/14
 * Time: 4:36 PM
 */

class Admin_Utility_Sitemap_Controller extends Base_Controller {

    public $restful = true;

    public function __construct()
    {
        parent::__construct();
        //--Your Code --//
        //$this->theme->set_theme("admin") ;
        //$this->theme->set_layout("default") ;
    }


    public function get_index(){



       $sitemap = new Sitemap();

        $sitemap->title = 'XML SITEMAP FOR : '.Settings::get('en', 'site_title');
        $sitemap->link = URL::base();

        $posts = DB::table('post')->order_by('id', 'desc')->take(100)->get();
        foreach ($posts as $post)
        {
            $loc = URL::base().'/'.Commoncall::postLink($post->id);
            $sitemap->add($loc, $post->updated_at, '2', 'weekly', $post->title);
        }

        // show your sitemap (options: 'xml' (default), 'html', 'txt', 'ror-rss', 'ror-rdf')
        return $sitemap->render('xml');
    }

    public function get_rss(){
        $sitemap = new Sitemap();

        $sitemap->title = 'RSS FOR : '.Settings::get('en', 'site_title');
        $sitemap->link = URL::base();

        $posts = DB::table('post')->order_by('id', 'desc')->take(100)->get();
        foreach ($posts as $post)
        {
            $loc = URL::base().'/'.Commoncall::postLink($post->id);
            $sitemap->add($loc, $post->updated_at, '2', 'weekly', $post->title);
        }

        // show your sitemap (options: 'xml' (default), 'html', 'txt', 'ror-rss', 'ror-rdf')
        return $sitemap->render('ror-rss');
    }

    public function get_rdf(){
        $sitemap = new Sitemap();

        $sitemap->title = 'RDF FOR : '.Settings::get('en', 'site_title');
        $sitemap->link = URL::base();

        $posts = DB::table('post')->order_by('id', 'desc')->take(100)->get();
        foreach ($posts as $post)
        {
            $loc = URL::base().'/'.Commoncall::postLink($post->id);
            $sitemap->add($loc, $post->updated_at, '2', 'weekly', $post->title);
        }

        // show your sitemap (options: 'xml' (default), 'html', 'txt', 'ror-rss', 'ror-rdf')
        return $sitemap->render('ror-rdf');
    }

    public function get_text(){
        $sitemap = new Sitemap();

        $sitemap->title = 'TEXT LINK FOR : '.Settings::get('en', 'site_title');
        $sitemap->link = URL::base();

        $posts = DB::table('post')->order_by('id', 'desc')->take(100)->get();
        foreach ($posts as $post)
        {
            $loc = URL::base().'/'.Commoncall::postLink($post->id);
            $sitemap->add($loc, $post->updated_at, '2', 'weekly', $post->title);
        }

        // show your sitemap (options: 'xml' (default), 'html', 'txt', 'ror-rss', 'ror-rdf')
        return $sitemap->render('text');
    }

    public function get_html(){
        $sitemap = new Sitemap();

        $sitemap->title = 'HTML LINK FOR : '.Settings::get('en', 'site_title');
        $sitemap->link = URL::base();

        $posts = DB::table('post')->order_by('id', 'desc')->take(100)->get();
        foreach ($posts as $post)
        {
            $loc = URL::base().'/'.Commoncall::postLink($post->id);
            $sitemap->add($loc, $post->updated_at, '2', 'weekly', $post->title);
        }

        // show your sitemap (options: 'xml' (default), 'html', 'txt', 'ror-rss', 'ror-rdf')
        return $sitemap->render('html');
    }

}
